package org.shilong.UI.party;

import org.shilong.UI.R;
import org.shilong.Utility.Loader.PartyListViewLoader;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.ListView;

/**
 * 新的新的聚会承载页面
 * 
 * @author cesc
 * 
 */
public class BrandShowNewPartyFrame extends Activity {

	private ListView showNewPariesListView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.new_layout_show_new_paries_content);

		listenBroadcast();

		initViews();
	}

	/**
	 * 初始化布局
	 */
	void initViews() {

		showNewPariesListView = (ListView) this
				.findViewById(R.id.show_new_party_listview);

		PartyListViewLoader loader = new PartyListViewLoader(
				showNewPariesListView, PartyListViewLoader.NEW_PARTY, this);

		loader.startTask();
	}

	void initEvents() {

	}

	void listenBroadcast() {

		IntentFilter filter = new IntentFilter(
				BrandPartyCenterFrame.ACTION_REFRESH_NEW_PAREIS_DATAS);

		registerReceiver(new RefreshDatasListener(), filter);

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub

		if (keyCode == KeyEvent.KEYCODE_BACK) {

			if (PartyListViewLoader.myPopWindow != null) {
				if (PartyListViewLoader.myPopWindow.isShowing()) {

					PartyListViewLoader.myPopWindow.dismiss();

					return true;
				}
			}

		}
		return super.onKeyDown(keyCode, event);
	}

	private class RefreshDatasListener extends BroadcastReceiver {

		@Override
		public void onReceive(Context content, Intent intent) {
			// TODO Auto-generated method stub

			System.out.println("启动异步获取新聚会数据.....");

			PartyListViewLoader loader = new PartyListViewLoader(
					showNewPariesListView, PartyListViewLoader.NEW_PARTY,
					BrandShowNewPartyFrame.this);

			loader.startTask();

		}
	}
}
